package com.pureut.equipment.controller;


import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.equipment.domain.dto.DeviceOperationDto;
import com.pureut.equipment.domain.dto.DeviceRecordDto;
import com.pureut.equipment.domain.vo.DeviceRecordVo;
import com.pureut.equipment.domain.vo.ReturnDeviceStatusVo;
import com.pureut.equipment.service.DeviceRecordService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: CM
 * @date: 2023/2/13  11:23
 */
@RestController
@RequestMapping("/device")
public class DeviceRecordController extends BaseController {

    @Resource
    private DeviceRecordService deviceRecordService;

    /**
     * 设备台账查询列表
     */
    @RequiresPermissions("device:equipment:list")
    @GetMapping("/list")
    public TableDataInfo list(DeviceRecordVo deviceRecordVo) {
        startPage();
        List<DeviceRecordDto> list = deviceRecordService.getList(deviceRecordVo);
        return getDataTable(list);
    }

    /**
     * 新增设备台账
     */
    @RequiresPermissions("system:shopAdministration:equipment:add")
    @Log(title = "新增设备台账  ", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody DeviceRecordVo deviceRecordVo) throws Exception {
        return toAjax(deviceRecordService.deviceAdd(deviceRecordVo));
    }

    /**
     * 修改设备台账
     */
    @RequiresPermissions("system:shopAdministration:equipment:edit")
    @Log(title = "修改设备台账", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody @Validated DeviceRecordVo deviceRecordVo) {
        return toAjax(deviceRecordService.deviceEdit(deviceRecordVo));
    }

    /**
     * 查看设备台账明细
     */
    @RequiresPermissions("system:shopAdministration:equipment:query")
    @GetMapping("/view")
    public AjaxResult view(long id) {
        return AjaxResult.success(deviceRecordService.view(id));
    }

    /**
     * 删除设备台账信息
     */
    @RequiresPermissions("system:shopAdministration:equipment:remove")
    @Log(title = "删除配置变量", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove")
    public AjaxResult remove(String ids) {
        return toAjax(deviceRecordService.remove(ids));
    }

    /**
     * 通过线别编码查看列表信息
     */
    @GetMapping("/getLine")
    public AjaxResult getLine(String lineCode) {
        return AjaxResult.success(deviceRecordService.getLine(lineCode));
    }

    /**
     * 通过设备编码查出设备名称,设备类型,设备属性
     */
    @GetMapping("/getDeviceInfo")
    public AjaxResult getDeviceInfo(String deviceCode) {
        return AjaxResult.success(deviceRecordService.getDeviceInfo(deviceCode));
    }

    /**
     * 查询设备运行情况(feign)
     */
    @GetMapping("/getDeviceCondition")
    public AjaxResult getDeviceCondition(String lineCode) {
        List<DeviceOperationDto> deviceCondition = deviceRecordService.getDeviceCondition(lineCode);
        return AjaxResult.success(deviceCondition);
    }

    /**
     * 设备状态回传（fegin）
     */
    @PostMapping("/returnDeviceStatus")
    public AjaxResult returnDeviceStatus(@RequestBody ReturnDeviceStatusVo returnDeviceStatusVo) {
        return toAjax(deviceRecordService.returnDeviceStatus(returnDeviceStatusVo));
    }

}
